home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
pascal
/
vmath10.zip
/
VMATH10.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-05-21
|
19KB
|
535 lines
{--------------------------------> Vmath <---------------------------------}
{ This unit contains vector and matrix procedures and functions for TURBO- }
{ PASCAL, partly written as inline assembler code for a 387 coprocessor. }
{ They are about two to three times faster than the equivalent "pure PASCAL" }
{ code. }
{ Known features/limitations/bugs etc.: }
{ - The unit has been written with TP6.0 on an 386SX/IIT387SX machine }
{ - The procedure MulM4V4 needs an IIT coprocessor }
{ - The 287 coprocessor needs additional FWAIT commands in of strategic }
{ places all over the code, since I don't have one I didn't bother. }
{ - All routines PUSH DS on entry, use long pointers (You don't want to }
{ be limited to 64K won't You ?) for operand access and POP DS on exit }
{ - No testing of the routines has been carried out except that they work }
{ fine and fast in my application - NO WARRANTY ! }
{ - I wrote the routines as I needed them (or as I wanted to find out how to }
{ do it, in the case of MulM4V4) but at least the Vector3 operations are }
{ quite complete by now. If I find the time some more Matrix3 code may }
{ follow. }
{----------------------------------------------------------------------------}
{ These routines contain no special artifice, but are straightforward }
{ coded "mathematical common knowledge", so everybody is free to copy }
{ and modify the whole unit or parts of it. And remember: Distributing }
{ sourcecode advances the "Art of Computing" by allowing others to learn }
{ from Your mistakes ! }
{----------------------------------------------------------------------------}
{ I would be pleased to get some feedback (comments/additions/questions or }
{ even a sample application using this unit) from users of Vmath -preferably }
{ via Email - Internet: mowl@cc.flinders.edu.au }
{ }
{ _--_|\ Wolfgang Lieff }
{ / \ Flinders Institute for Atmospheric and Marine Sciences }
{ \_.--x_/ Bedford Park , South Australia 5042 }
{ v }
{----------------------------------------------------------------------------}
{ Version 1.0 of 20/05/1991 by Wolfgang Lieff }
{----------------------------------------------------------------------------}
unit Vmath10;
interface
type Matrix4 = array[0..3,0..3] of double;
Vector4 = array[0..3] of double;
Matrix3 = array[0..2,0..2] of double;
Vector3 = array[0..2] of double;
const
ZeroV3 : Vector3 = (0.0,0.0,0.0);
XunityV3 : Vector3 = (1.0,0.0,0.0);
YunityV3 : Vector3 = (0.0,1.0,0.0);
ZunityV3 : Vector3 = (0.0,0.0,1.0);
{----------------------------------------------------------------------------}
procedure DirectionV3(P1,P2:Vector3; var R:Vector3);
{ =========== }
{ Function Calculates the unity direction vector from P1 to P2 }
{ }
{ Result type Vector3 }
{----------------------------------------------------------------------------}
procedure MulV3V3(V1,V2:Vector3; var R:Vector3);
{ ======= }
{ Function Multiplies the components of two vectors }
{ }
{ Result type Vector3 }
{----------------------------------------------------------------------------}
function MulV3(V1,V2:Vector3):double;
{ ===== }
{ Function Scalar multiplication (dot product) of two vectors }
{ }
{ Result type double }
{----------------------------------------------------------------------------}
procedure CrossV3(V1,V2:Vector3; var R:Vector3);
{ ======= }
{ Function Vector multiplication (cross product) of two vectors }
{ }
{ Result type Vector3 }
{----------------------------------------------------------------------------}
procedure NormalizeV3(var V:Vector3);
{ =========== }
{ Function Transforms a vector into a unity vector with the same }
{ direction }
{ }
{ Result type Vector }
{----------------------------------------------------------------------------}
function AbsV3(V:Vector3):double;
{ ===== }
{ Function Returns the length of a vector }
{ }
{ Result type double }
{----------------------------------------------------------------------------}
function QuickAbsV3(V:Vector3):double;
{ ========== }
{ Function Returns a rough estimate of the length of a vector }
{ by simply adding the absolute values of the components}
{ }
{ Result type double }
{----------------------------------------------------------------------------}
procedure MulV3D(V:Vector3; S:double; var R:Vector3);
{ ====== }
{ Function Multiplies the components of a vector with a scalar }
{ }
{ Result type Vector3 }
{----------------------------------------------------------------------------}
procedure DivV3D(V:Vector3; S:double; var R:Vector3);
{ ====== }
{ Function Divides the components of a vector by a scalar }
{ }
{ Result type double }
{----------------------------------------------------------------------------}
procedure DivV3V3(V1,V2:Vector3; R:Vector3);
{ ======= }
{ Function Divides the components of two vectors }
{ }
{ Result type double }
{----------------------------------------------------------------------------}
procedure AddV3(V1,V2:Vector3; var R:Vector3);
{ ===== }
{ Function Adds two vectors }
{